package com.ukao.cashregister.doubleScreen;

import android.app.Presentation;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
import android.os.IBinder;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import android.view.Display;
import android.view.WindowManager;

/**
 * Created by herego on 2017/6/28.
 */

public class DoubleScreenService extends Service {
    private DisplayManager mDisplayManager;
    private Display[] displays;
    private final SparseArray<Presentation> mActivePresentations = new SparseArray<Presentation>();
    private Presentation mPresentation;

    @Override
    public void onCreate() {
        super.onCreate();
        mDisplayManager = (DisplayManager)getSystemService(Context.DISPLAY_SERVICE);
        displays = mDisplayManager.getDisplays();
        mPresentation = new DemoPresentation(this,displays[1]);
        mActivePresentations.append(1,mPresentation);
        mPresentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        mPresentation.show();



    }



    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Presentation presentation = mActivePresentations.get(1);
        presentation.dismiss();
        stopSelf();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
